﻿package com.eitb.programas.streamingUefa.botones{
	import com.eitb.botones.*;
	import flash.text.*;
	import flash.events.*;
	import flash.display.*;
	import com.eitb.bitmaps.*;
	public class VolumeIcon extends Boton {
		private var volumeOn:Bitmap;
		private var volumeOff:Bitmap;
		private var sound:Boolean;
		private var actualSound:Number;
		private var barra:MovieClip;
		
		public function VolumeIcon():void {
			this.sound = true;
			this.initIconoOn();
			this.initIconoOff();
			this.addEventListener(MouseEvent.MOUSE_DOWN,downBoton);
		}
		private function initIconoOn():void {			
			this.volumeOn = new Bitmap(new VolumeOn());
			this.volumeOn.visible = true;
			this.addChild(this.volumeOn);
		}
		private function initIconoOff():void {			
			this.volumeOff = new Bitmap(new VolumeOff());
			this.volumeOff.visible = false;
			this.addChild(this.volumeOff);
		}
		public function initBarra(barra:MovieClip):void {
			this.barra = barra;
		}		
		private function downBoton(event:MouseEvent):void {
			this.sound = !this.sound;
			if (this.sound) {
				this.switchVisibleIcon();
				this.barra.width = this.actualSound;
			} else {
				this.actualSound = this.barra.width;
				this.switchVisibleIcon();
				this.barra.width = 0;
			}
		}
		private function switchVisibleIcon():void{
			this.volumeOn.visible = !this.volumeOn.visible;
			this.volumeOff.visible = !this.volumeOff.visible;
		}
	}
}